package com.bing.dao;

import com.bing.bean.weixin.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by kaibb on 2014/12/9.
 */

@Repository
public interface AccountDao {
    @Select("select * from Account where accountType=#{accountType} and accountStatus=#{accountStatus}")
    List<Account> findByTSS(@Param("accountType") AccountType accountType, @Param("accountStatus") AccountStatus accountStatus);

    @Select("select * from Account where url=#{url}")
    @Results(
    @Result(property = "commands", column = "id",many = @Many(select = "com.bing.dao.CommandDao.findCommandsByAccountId")))
    Account findByUrl(String url);

    @Select("select u.* from User u, AccountUser ac where ac.accountId=#{id} and u.id = ac.userId")
    List<User> findUsers(Account account);
    @Select("select * from Account")
    List<Account> findAccounts();

    @Select("select m.* from Message m,AccountCommand ac where m.id = ac.msgId and ac.accountId=#{id}")
    @Results(
            {@Result(property = "id", column = "id"),
                    @Result(property = "articles", column = "id",
                            many = @Many(select = "com.bing.dao.ArticleDao.getArticlesByMsgId")),
                    @Result(property = "image", column = "msgId",
                            one = @One(select = "com.bing.dao.MediaDao.findById"))
            }
    )    List<ResponseMessage> findCommands(Account account);
}
